const fs = require('fs');
const express = require('express');
const bodyParser = require('body-parser');
const router = express.Router();
const app = express()
const refreshToken = require('../wx_server/getWebToken');

const getJsApiData = require('../wx_server/getJsApiData')
const config = require('../config');
refreshToken()

app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());

/* GET users listing. */
router.get('/', function(req, res)  {
    const currentToken = fs.readFileSync('./token').toString();
    const currentTicket = fs.readFileSync('./ticket').toString();
    // console.log('gettoken' + currentTicket)
    var clientUrl =  decodeURIComponent(req.query.url);
    // logger.info("请求传递的URL 和 获取到的token == ",clientUrl + '   +++    ' + currentToken)
    setTimeout(function () {
        var apidata = getJsApiData(clientUrl,currentToken,currentTicket)
        console.log("获取签名、时间戳 、noncestr、ticket == " + apidata)
        res.jsonp({signature: apidata[0], timestamp: apidata[1], noncestr: apidata[2], appId: config.wx_config.AppID});

    },1000)
})


module.exports = router;
